// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "DBManager/DBAPI.h"

#include <gtest/gtest.h>

#include "DataStructure/Input/Element/CFASTData.h"
#include "DataStructure/Input/Element/CWELDData.h"

#include "DBManager/IService/Input/Element/IElementService.h"
#include "DBManager/IService/Input/Node/INodeService.h"
#include "DBManager/UnitTest/HDF5/TestDB.h"

using namespace SG::DBManager;

TEST (I_DBAPITest, GetAllNodeId)
{
    DB::ServiceFactory->ClearDatabase ();

    std::vector<SG::DataStructure::Common::Id> ids = { 45, 17, 92, 3, 78, 54, 29, 63, 10, 87, 36, 50, 19, 71, 8, 96, 12, 68, 25, 41 };

    // 添加数据
    SG::DataStructure::FEM::NodeData node;

    const auto& nodeService    = DB::ServiceFactory->get<INodeService> ();
    const auto& elementService = DB::ServiceFactory->get<IElementService> ();

    for (auto i = 0; i < static_cast<SG::DataStructure::Common::Id> (ids.size ()); i++)
    {
        node.m_id = ids[i];
        nodeService->Add (node);
    }

    SG::DataStructure::FEM::CWELDData cweld1;
    cweld1.m_id   = 1;
    cweld1.m_g[0] = 102e+6;
    cweld1.m_g[1] = 103e+6;

    SG::DataStructure::FEM::CWELDData cweld2;
    cweld2.m_id   = 2;
    cweld2.m_g[0] = 104e+6;
    cweld2.m_g[1] = 105e+6;

    SG::DataStructure::FEM::CFASTData cfast1;
    cfast1.m_id   = 3;
    cfast1.m_g[0] = 106e+6;
    cfast1.m_g[1] = 107e+6;

    elementService->Add (cweld1);
    elementService->Add (cweld2);
    elementService->Add (cfast1);

    // 查询数据
    auto allNodeId = DBAPI::GetAllNodeId (DB::ServiceFactory);
    ASSERT_EQ (allNodeId.size (), ids.size () + 6);
    ASSERT_EQ (allNodeId.back (), 107e+6);
}